package cn.edu.zut.internship.service.impl.notify;

import cn.edu.zut.internship.bean.sys.Result;
import cn.edu.zut.internship.bean.sys.SysUser;
import cn.edu.zut.internship.iservice.company.CompanySV;
import cn.edu.zut.internship.iservice.notify.NotifySV;
import cn.edu.zut.internship.mapper.company.CompanyMapper;
import cn.edu.zut.internship.mapper.notify.NotifyMapper;
import cn.edu.zut.internship.utils.PrimaryKeyUtil;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class NotifySVImpl implements NotifySV {
    @Autowired
    private NotifyMapper notifyMapper;
    @Autowired
    PrimaryKeyUtil primaryKeyUtil;
    @Autowired
    CompanyMapper companyMapper;
    @Override
    public Result getNotifyById(Long notifyId) {
        Result result = new Result();
        Map notify = notifyMapper.getNotify(notifyId);
        result.setBean(notify);
        return result;
    }

    @Override
    public Result selectNotify(Map params) {
        Result result = new Result();
        List<Map> list = notifyMapper.getList(params);
        int total = notifyMapper.getListCount(params);
        result.setBeans(list);
        result.getBean().put("total",total);
        return result;
    }
    @Override
    public Result addNotify(Map params){
        Result result = new Result();
        Long notifyId = primaryKeyUtil.generatePrimaryKey("notify");
        params.put("notifyId",notifyId);
        notifyMapper.addNotify(params);
        return result;
    }
    @Override
    public Result delectNotify(Long notifyId) {
        Result result = new Result();
        notifyMapper.deleteNotify(notifyId);
        return result;
    }

    @Override
    public Result updateNotify(Map params) {
        Result result = new Result();
        notifyMapper.updateNotify(params);
        return result;
    }
    @Override
    public Result getNotifyNum(String userAccount){
        Result result = new Result();
        int notifyNum = notifyMapper.getNotifyNum(userAccount);
        result.getBean().put("notifyNum",notifyNum);
        return result;
    }

    @Override
    public Result deleteAll(String userAccount) {
        Result result = new Result();
        notifyMapper.deleteAll(userAccount);
        return result;
    }

    @Override
    public Result redAll(String userAccount) {
        Result result = new Result();
        notifyMapper.redAll(userAccount);
        return result;
    }

    @Override
    public Result redNotify(Map params) {
        Result result = new Result();
        notifyMapper.readeNotify(params);
        return result;
    }

    @Override
    public Result remindAdmin(Map params) {
        Result result = new Result();
        Map notify = new HashMap();
        Map companyById = companyMapper.getCompany(params);
        SysUser userInfo = (SysUser) params.get("userInfo");
        notify.put("sendAccount",userInfo.getUserAccount());
        notify.put("sendType",0);
        notify.put("notifyType",5);
        notify.put("internshipId",params.get("internshipId"));
        notify.put("content","学生"+userInfo.getUserName()+"提醒您及时审核实训单位:"+companyById.get("internshipName"));
        notify.put("targetAccount","admin");
        notify.put("targetType",0);
        notify.put("creatAccount",params.get("teachAccount"));
        addNotify(notify);
        return result;
    }
}
